package com.zzedu.controller;

import com.zzedu.common.annotation.Log;
import com.zzedu.common.core.controller.BaseController;
import com.zzedu.common.core.domain.AjaxResult;
import com.zzedu.common.core.page.TableDataInfo;
import com.zzedu.common.enums.BusinessType;
import com.zzedu.common.utils.ServletUtils;
import com.zzedu.common.utils.poi.ExcelUtil;
import com.zzedu.domain.ZzExerciseBookSubmitContent;
import com.zzedu.dto.ZzExerciseBookSubmitContentDTO;
import com.zzedu.service.IZzExerciseBookSubmitContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 作业内容Controller
 * 
 * @author Mr.Wang
 * @date 2025-06-02
 */
@RestController
@RequestMapping("/exercise/content")
public class ZzExerciseBookSubmitContentController extends BaseController
{
    @Autowired
    private IZzExerciseBookSubmitContentService zzExerciseBookSubmitContentService;

    /**
     * 查询作业内容列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('exercise:content:query')")
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody ZzExerciseBookSubmitContentDTO zzExerciseBookSubmitContent)
    {
        return getDataTable(zzExerciseBookSubmitContentService.page(zzExerciseBookSubmitContent.getPageDTO(),zzExerciseBookSubmitContentService.buildQuery(zzExerciseBookSubmitContent)));
    }

    /**
     * 导出作业内容列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('exercise:content:export')")
    @Log(title = "作业内容", businessType = BusinessType.EXPORT)
    @RequestMapping("/export")
    public void export(ZzExerciseBookSubmitContentDTO zzExerciseBookSubmitContent)
    {
        List<ZzExerciseBookSubmitContent> list = zzExerciseBookSubmitContentService.list(zzExerciseBookSubmitContentService.buildQuery(zzExerciseBookSubmitContent));
        ExcelUtil<ZzExerciseBookSubmitContent> util = new ExcelUtil<ZzExerciseBookSubmitContent>(ZzExerciseBookSubmitContent.class);
        util.exportExcel(ServletUtils.getResponse(),list, "作业内容数据");
    }




    /**
     * 新增保存作业内容
     */
    @PreAuthorize("@permission.hasAnyPermissions('exercise:content:add')")
    @Log(title = "作业内容", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    public AjaxResult addSave(@Validated @RequestBody ZzExerciseBookSubmitContent zzExerciseBookSubmitContent)
    {
        return toAjax(zzExerciseBookSubmitContentService.save(zzExerciseBookSubmitContent));
    }



    /**
     * 获取作业内容详细信息
     */
    @PreAuthorize("@permission.hasAnyPermissions('exercise:content:query')")
    @RequestMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zzExerciseBookSubmitContentService.getById(id));
    }


    /**
     * 修改保存作业内容
     */
    @PreAuthorize("@permission.hasAnyPermissions('exercise:content:edit')")
    @Log(title = "作业内容", businessType = BusinessType.UPDATE)
    @RequestMapping("/edit")
    public AjaxResult editSave(@Validated @RequestBody ZzExerciseBookSubmitContent zzExerciseBookSubmitContent)
    {
        return toAjax(zzExerciseBookSubmitContentService.updateById(zzExerciseBookSubmitContent));
    }

    /**
     * 删除作业内容
     */
    @PreAuthorize("@permission.hasAnyPermissions('exercise:content:remove')")
    @Log(title = "作业内容", businessType = BusinessType.DELETE)
	@RequestMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(zzExerciseBookSubmitContentService.removeBatchByIds(ids));
    }
}
